<template>
  <div>
    <div class="gva-search-box">
      <el-form :model="formData" ref="elFormRef" label-position="right" :inline="false">
        <el-form-item label="用户协议:"></el-form-item>
        <el-form-item prop="user_agreement">
          <RichEdit v-model="formData.user_agreement" />
        </el-form-item>
		<el-form-item label="隐私协议:"></el-form-item>
		<el-form-item prop="privacy_agreement">
		  <RichEdit v-model="formData.privacy_agreement" />
		</el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script setup>
import { onMounted, reactive, ref } from "vue";
import { financialAgreement } from "@/api/subscribe";
import RichEdit from "@/components/richtext/rich-edit.vue";
import { ElMessage } from "element-plus";

const formData = ref({
  user_agreement: "",
  privacy_agreement:""
});
const elFormRef = ref();
onMounted(() => {
  getFinancialDetail();
});
const getFinancialDetail = () => {
  financialAgreement().then(response => {
    if (response.code === 200) {
      formData.value.user_agreement = response.data.user_agreement;
      formData.value.privacy_agreement = response.data.privacy_agreement;
    }
  });
};
const save = () => {
  let params = {
    user_agreement: formData.value.user_agreement,
    privacy_agreement: formData.value.privacy_agreement,
  };
  elFormRef.value.validate(async valid => {
    if (valid) {
      financialAgreement(params).then(response => {
        if (response.code === 200) {
          ElMessage({
            message: "操作成功",
            type: "success"
          });
        }
      });
    }
  });
};
</script>
<style lang="scss" scoped>
.gva-search-box {
  // height: 50vh;
  overflow: auto;
}
</style>
